package felix.things.router.mqtt.server.broker.protocol;

import felix.things.router.mqtt.server.common.message.IDupPublishMessageStoreService;
import felix.things.router.mqtt.server.common.message.IMessageIdService;
import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;

/**
 * PUBACK连接处理
 *
 * @author Felix
 * @date 2019/8/21
 */
@Slf4j
public class PubAck {

    private IDupPublishMessageStoreService dupPublishMessageStoreService;

    public PubAck(IDupPublishMessageStoreService dupPublishMessageStoreService) {
        this.dupPublishMessageStoreService = dupPublishMessageStoreService;
    }

    public void processPubAck(Channel channel, MqttMessageIdVariableHeader variableHeader) {
        int messageId = variableHeader.messageId();
        log.debug("PUBACK - clientId: {}, messageId: {}", (String) channel.attr(AttributeKey.valueOf("clientId")).get(), messageId);
        dupPublishMessageStoreService.remove((String) channel.attr(AttributeKey.valueOf("clientId")).get(), messageId);
    }

}
